<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //includes()判断字符串中是否包含某些字符
        console.log('abc'.includes('a')); //true
        console.log('abcd'.includes('abc')); //true
        console.log('abcs'.includes('f')); //false

        //第二个参数
        //表示开始搜索的位置默认是0
        console.log('abc'.includes('a', 0)); //true
        console.log('abc'.includes('a', 1)); //false


        //在实际开发中的应用
        //https://www.imooc.com/course/list
        //https://www.imooc.com/course/list?c=fe&sort=pop&name=value
        let url = 'https:www.imooc.com/course/list';
        const addURLParam = (url, name, value) => {
            url += url.includes('?') ? '&' : '?';
            url += `${name}=${value}`
            return url;
        }
        url = addURLParam(url, 'c', 'fe')
        url = addURLParam(url, 'sort', 'pop')

        console.log(url);
    </script>
</body>

</html>